<?php
 Session_Start () ;
 If (!$_SESSION ["repertoire_config"]) { Header ("Location: ../../sortie.php?sortie=3") ; }
 Include ("../../include/garennes.cfg") ;
 Include ("../../include/init.php") ;
 Include ("../include/config.inc") ;
 verif_droits ($droit_courant, $_SESSION ["code"]) ;

 Include ("../../include/garennes_bdd.cfg") ;
 
 $resultats = SQL_commande ("SELECT * FROM menus WHERE numero='".$droit_courant."' AND ordre='0'", $id_sql) ;
 $l = SQL_tableau_associatif ($resultats, "") ;  
 
 Echo "<html><head>" ;
 entete_html ("Garennes - Optimisation des bases de donn&eacute;es", "travail", 1) ;
 Echo styles ("none", "none", "none", $l ["couleur_fond"], "none") ;
 Echo "</head>" ;
 
 Echo "<body background=\"../images/fond.png\" text=\"#000000\" OnContextMenu=\"return false\">" ;
 Echo "<center><font color=\"#0000FF\">Optimisation&nbsp;des&nbsp;bases&nbsp;de&nbsp;donn&eacute;es</font></center>" ;
 Echo "<table border=\"1\" bgcolor=\"".$l ["couleur_fond"]."\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\" style=\"border-collapse:collapse;border:1px solid #000000\">" ;
 Echo "<tr bgcolor=\"".$l ["lien"]."\">" ;
 Echo "<td align=\"center\">&nbsp;<b>Base</b>&nbsp;</td>" ;
 Echo "<td align=\"center\">&nbsp;<b>V&eacute;rification</b>&nbsp;</td>" ;
 Echo "<td align=\"center\">&nbsp;<b>R&eacute;paration</b>&nbsp;</td>" ;
 Echo "<td align=\"center\">&nbsp;<b>Optimisation</b>&nbsp;</td>" ;
 Echo "</tr>" ;
 For ($i = 1 ; $i <= $bdd [0][0] ; $i++)
  {
   $id_bdd = SQL_etablissement_connexion ($sql_adresse, $sql_qui, $sql_passe, $sql_port) ;
   $selection = SQL_selection_bd ($bdd [$i][1], $id_bdd) ;
   If ($selection)
    {
     $resultats = SQL_commande ("SHOW TABLES", $id_bdd) ;
     For ($j = 0 ; $j < SQL_nbr_lignes ($resultats) ; $j++)
      {
       $ligne = SQL_ligne_suivante ($resultats) ;
       $opt = SQL_commande ("CHECK TABLE ".$ligne [0], $id_bdd) ;
       //$l = SQL_tableau_associatif ($opt, "") ;
       $opt = SQL_commande ("REPAIR TABLE ".$ligne [0], $id_bdd) ;
       //$l = SQL_tableau_associatif ($opt, "") ;
       $opt =   SQL_commande ("OPTIMIZE TABLE ".$ligne [0], $id_bdd) ;
       //$l = SQL_tableau_associatif ($opt, "") ;
      }
     Echo "<tr><td>&nbsp;".$bdd [$i][1]."&nbsp;</td><td align=\"center\">&nbsp;Fait&nbsp;</td>" ;
     Echo "<td align=\"center\">&nbsp;Fait&nbsp;</td><td align=\"center\">&nbsp;Fait&nbsp;</td></tr>" ;
     $ok = SQL_fermeture ($id_bdd) ;
    }
   Else
    {
     Echo "<tr><td>&nbsp;".$bdd [$i][1]."&nbsp;</td><td align=\"center\">&nbsp;NON&nbsp;Fait&nbsp;</td>" ;
     Echo "<td align=\"center\">&nbsp;NON&nbsp;Fait&nbsp;</td><td align=\"center\">&nbsp;NON&nbsp;Fait&nbsp;</td></tr>" ;
    }
  }
 Echo "</table></body></html>" ;
?>